﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using SubSonic.SqlGeneration.Schema;
using System.Xml;
using System.Xml.Serialization;
#endregion

namespace eTerm.MsSql.DbProvider{
    /// <summary>
    /// 文 件 名: VErpTicketNo.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 未定义
    /// 生成日期: 2013年8月2日
    /// </summary>
    [SubSonicTableNameOverride(@"V_ERP_TicketNo")]
    public partial class VErpTicketNo{
        
        #region 变量定义
        private bool isLoaded=false;
        private bool isNew=false;
        private List<IColumn> dirtyColumns;
        IRepository< VErpTicketNo > _repo;
        ITable tbl;
        private static IQuerySurface _db;
        #endregion
        
        #region 构造函数
        /// <summary>
        /// 初始化一个新实例 <see cref="VErpTicketNo"/>.
        /// <param name="dbProvider">采用注入式数据库配置初始化.</param>
        /// </summary>
        public VErpTicketNo(IQuerySurface dbProvider){
            if (dbProvider != null) {
                _db = dbProvider;
                Init();
            }
        }
        
        /// <summary>
        /// 初始化一个新实例 <see cref="VErpTicketNo"/>.
        /// </summary>
        public VErpTicketNo(){
            if(_db==null)
                _db = Context.Instance.DbProvider;
            if(_db!=null)
                Init();
        }
        
        
        /// <summary>
        /// 实例内部初始化逻辑.
        /// </summary>
        void Init(){
            _repo = new SubSonicRepository< VErpTicketNo >(_db);
            tbl=_repo.GetTable();
            dirtyColumns=new List<IColumn>();
        }
        #endregion
        
        #region 生成IRepository
        internal static IRepository< VErpTicketNo > GetRepo(){
            if (_db == null)
                _db = Context.Instance.DbProvider;
            IRepository< VErpTicketNo > _repo;
            _repo = new SubSonicRepository< VErpTicketNo >(_db);
            return _repo;         
        }       
        #endregion
        
        #region VErpTicketNo属性列表
        System.Int64 m_Id;
        /// <summary>
        /// 未定义
        ///</summary>
        [SubSonicPrimaryKey]
        [XmlAttribute()]
        public System.Int64 Id
        {
            get { return m_Id; }
            set{
                m_Id=value;
            }
        }
        
        System.String m_TradeNo;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String TradeNo
        {
            get { return m_TradeNo; }
            set{
                m_TradeNo=value;
            }
        }
        
        System.DateTime m_TradeDate;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.DateTime TradeDate
        {
            get { return m_TradeDate; }
            set{
                m_TradeDate=value;
            }
        }
        
        System.String m_TicketNo;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String TicketNo
        {
            get { return m_TicketNo; }
            set{
                m_TicketNo=value;
            }
        }
        
        System.DateTime m_TicketDate;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.DateTime TicketDate
        {
            get { return m_TicketDate; }
            set{
                m_TicketDate=value;
            }
        }
        
        System.String m_TradeType;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String TradeType
        {
            get { return m_TradeType; }
            set{
                m_TradeType=value;
            }
        }
        
        System.String m_UserNo;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.String UserNo
        {
            get { return m_UserNo; }
            set{
                m_UserNo=value;
            }
        }
        
        System.Int32 m_UserId;
        /// <summary>
        /// 未定义
        ///</summary>
        [XmlAttribute()]
        public System.Int32 UserId
        {
            get { return m_UserId; }
            set{
                m_UserId=value;
            }
        }
        
        #endregion
               
        #region 静态方法
        /// <summary>
        /// 按条件获取 "未定义" 单实体 .
        /// </summary>
        /// <param name="expression">条件表达式.</param>
        /// <returns></returns>
        public static VErpTicketNo FirstOrDefault(Expression<Func< VErpTicketNo, bool>> expression) {
            var repo = GetRepo();
            var results = repo.Find(expression);
            VErpTicketNo single = null;
            //if (results.Count() > 0) 
            {
                single = results.FirstOrDefault();
            }
            return single;
        }      
        

        /// <summary>
        /// 查询所有 "未定义" 数据
        /// </summary>
        /// <returns></returns>
        public static IQueryable<VErpTicketNo> All() {
            return GetRepo().GetAll();
        }

        /// <summary>
        /// 查询对象：未定义 .
        /// </summary>
        /// <value>未定义.</value>
        [Browsable(false)]
        public static IQueryable< VErpTicketNo > QURYVErpTicketNo(Expression<Func< VErpTicketNo, bool>> predicate)
        {
            return VErpTicketNo.All().Where(predicate);
        }
        

        /// <summary>
        /// 查询分页数据.
        /// </summary>
        /// <param name="sortBy">排序表达式</param>
        /// <param name="pageIndex">页次.</param>
        /// <param name="pageSize">页面大小</param>
        /// <returns></returns>
        public static PagedList<VErpTicketNo> GetPaged(string sortBy, int pageIndex, int pageSize) {
            return GetRepo().GetPaged(sortBy, pageIndex, pageSize);
        }


        /// <summary>
        /// 查询分页数据.
        /// </summary>
        /// <param name="pageIndex">页次.</param>
        /// <param name="pageSize">页面大小</param>
        /// <returns></returns>
        public static PagedList<VErpTicketNo> GetPaged(int pageIndex, int pageSize) {
            return GetRepo().GetPaged(pageIndex, pageSize);

        }
        
        /// <summary>
        /// 记录是否存在.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        public static bool Exists(Expression<Func<VErpTicketNo, bool>> expression) {
            return All().Any(expression);
        }
        
        
        /// <summary>
        /// 数据条件分页查询.
        /// </summary>
        /// <param name="expression">条件表达式.</param>
        /// <param name="pageIndex">页次.</param>
        /// <param name="pageSize">页面大小.</param>
        /// <returns></returns>
        public static IList<VErpTicketNo> Find(Expression<Func<VErpTicketNo, bool>> expression, int? pageIndex, int? pageSize) {
            var repo = GetRepo();
            IQueryable<VErpTicketNo> query = repo.Find(expression);
            if (pageIndex.HasValue) {
                query = query.Take(pageSize ?? 10);
                query = query.Skip(((pageIndex ?? 0) - 1) * pageSize ?? 10);
            }
            return query.ToList();
        }

        /// <summary>
        /// 数据条件分页查询.
        /// </summary>
        /// <param name="expression">条件表达式.</param>
        /// <returns></returns>
        public static IList<VErpTicketNo> Find(Expression<Func<VErpTicketNo, bool>> expression) {
            return Find(expression, null, null);
        }
        #endregion
    }
} 



